package com.example.demo0331.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.example.demo0331.entity.Goods;
import com.example.demo0331.entity.Shop;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface GoodsMapper extends BaseMapper<Goods> {

    @Select("select id, name, price, shop_id from goods where shop_id =#{shop_id}")
    public List<Goods> selectByShopId(int shop_id);

    @Select("select id, name, price, shop_id from goods")
    @Results({
            @Result(column = "id", property = "id"),
            @Result(column = "name", property = "name"),
            @Result(column = "price", property = "price"),
            @Result(column = "shop_id", property = "shopId"),
            @Result(column = "shop_id", property = "shop", javaType = Shop.class,
                one = @One(select = "com.example.demo0331.mapper.ShopMapper.findById")
            )
    })
    public List<Goods> all();
}
